﻿@{
    ViewBag.Title = "AddMessage";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<script>
    $(document).ready(function () {
        Projectshow();
        UserShow();
        $("#ButAdd").click(function () {
            var projectid = $("#project").val();
            var lixiang = $("#lixiang").val();
            var fangan = $("#fangan").val();
            var chengben = $("#chengben").val();
            var caiwu = $("#caiwu").val();
            var gongcheng = $("#gongcheng").val();
            var lixiangid = $("#lixiang").find("option:selected").attr("lixiang");
            var fanganid = $("#fangan").find("option:selected").attr("fangan");
            var chengbenid = $("#chengben").find("option:selected").attr("chengben");
            var caiwuid = $("#caiwu").find("option:selected").attr("caiwu");
            var gongchengid = $("#gongcheng").find("option:selected").attr("gongcheng");
            if (projectid == 0) {
                $("#tishi").html("请选择项目!");
                return;
            }
            else if (lixiangid==undefined)
            {
                $("#tishi").html("请选择立项负责人!");
                return;
            }
            else if (fanganid == undefined) {
                $("#tishi").html("请选择方案负责人!");
                return;
            }
            else if (chengbenid == undefined) {
                $("#tishi").html("请选择成本负责人!");
                return;
            }
            else if (caiwuid == undefined) {
                $("#tishi").html("请选择财务负责人!");
                return;
            }
            else if (gongchengid == undefined) {
                $("#tishi").html("请选择工程负责人!");
                return;
            }
            else {
                $.ajax({
                    type: "get",
                    url: "/Home/AddMemberTypes",
                    data: {
                        "projectid":projectid,
                        "lixiang": lixiang,
                        "fangan": fangan,
                        "chengben": chengben,
                        "caiwu": caiwu,
                        "gongcheng": gongcheng,
                        "lixiangid": lixiangid,
                        "fanganid": fanganid,
                        "chengbenid": chengbenid,
                        "caiwuid": caiwuid,
                        "gongchengid": gongchengid
                    },
                    success: function (d) {
                        if (d > 0) {
                            alert("分配成功！");
                        }
                        else {
                            alert("分配失败");
                        }
                    }
                });
            }
            
        });
    });
    //新项目显示
    function Projectshow()
    {
        $.ajax({
            type: "get",
            url: "/Home/ProjectDrop",
            data: {
            },
            success: function (d) {
                $(d).each(function (i,obj) {
                    var Project = "<option value="+obj.Id+">"+obj.ProjectName+"</option>";
                    $("#project").append(Project);
                });
            }
        });
    }
    //用户显示
    function UserShow() {
        $.ajax({
            type: "get",
            url: "/Home/UserShows",
            data: {
            },
            success: function (d) {
                $(d).each(function (i, obj) {
                    var LiXiangName = "<option value='1' lixiang=" + obj.Id + ">" + obj.Name + "</option>";
                    var FangAnName = "<option value='2' fangan=" + obj.Id + ">" + obj.Name + "</option>";
                    var ChengBenName = "<option value='3' chengben="+obj.Id+">" + obj.Name + "</option>";
                    var CaiWuName = "<option value='4' caiwu=" + obj.Id + ">" + obj.Name + "</option>";
                    var GongChengName = "<option value='5' gongcheng=" + obj.Id + ">" + obj.Name + "</option>";
                    $("#lixiang").append(LiXiangName);
                    $("#fangan").append(FangAnName);
                    $("#chengben").append(ChengBenName);
                    $("#caiwu").append(CaiWuName);
                    $("#gongcheng").append(GongChengName);
                });
            }
        });
    }
</script>
<h2>Add Member</h2>
<table id="tab" class="table table-condensed">
    <tr>
        <td>选择项目：</td>
        <td>
            <div class="control-group">
                <div class="controls">
                    <select id="project">
                        <option value="0">--请选择--</option>
                    </select>
                </div>
            </div>
        </td>
    </tr>
    <tr>
        <td>立项负责人：</td>
        <td>
            <div class="control-group">
                <div class="controls">
                    <select id="lixiang">
                        <option value="0">--请选择--</option>
                    </select>
                </div>
            </div>
        </td>
    </tr>
    <tr>
        <td>方案负责人：</td>
        <td>
            <div class="control-group">
                <div class="controls">
                    <select id="fangan">
                        <option value="0">--请选择--</option>

                    </select>
                </div>
            </div>
        </td>
    </tr>
    <tr>
        <td>成本负责人：</td>
        <td>
            <div class="control-group">
                <div class="controls">
                    <select id="chengben">
                        <option value="0">--请选择--</option>

                    </select>
                </div>
            </div>
        </td>
    </tr>
    <tr>
        <td>财务负责人：</td>
        <td>
            <div class="control-group">
                <div class="controls">
                    <select id="caiwu">
                        <option value="0">--请选择--</option>

                    </select>
                </div>
            </div>
        </td>
    </tr>
    <tr>
        <td>工程负责人：</td>
        <td>
            <div class="control-group">
                <div class="controls">
                    <select id="gongcheng">
                        <option value="0">--请选择--</option>
                    </select>
                </div>
            </div>
        </td>
    </tr>
    <tr>
        <td></td>
        <td><span style="color:red" id="tishi">*</span></td>
    </tr>
    <tr>
        <td></td>
        <td><input id="ButAdd" type="button" value="提交" /></td>
    </tr>
</table>

